package sut;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class Fichero {
	FileInputStream f;
	String text;
	
	public Fichero(String fileName) {
		try {
			this.text="";
			this.f=new FileInputStream(fileName);
		} catch (FileNotFoundException e) {
			this.text=e.toString();
		}
	}

	public String show() {
		if (this.text.length()>0) {
			System.out.println(this.text);
			return this.text;
		}
		try {
			byte[] b=new byte[this.f.available()];
			f.read(b);
			this.text=new String(b);
			System.out.println(this.text);
		} catch (IOException e) {
			this.text=e.toString();
			System.out.println(this.text);
		}
		return this.text;
	}

	public void close() {
		try {
			this.f.close();
		} catch (IOException e) {
			this.text=e.toString();
		}
	}

	public void create(String fileName) {
		try {
			FileOutputStream fos=new FileOutputStream(fileName);
			fos.write(fileName.getBytes());
			fos.close();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void create(String fileName, int off, int len) {
		try {
			FileOutputStream fos=new FileOutputStream(fileName);
			fos.write(fileName.getBytes(), off, len);
			fos.close();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	private boolean append;
	
	public void write(byte b[]) throws IOException {
		writeBytes(b, 0, b.length);
		writeBytes(b, 0, b.length, true);
	}

	private void writeBytes(byte[] b, int i, int length, boolean c) {
		// TODO Auto-generated method stub
		
	}

	private void writeBytes(byte[] b, int i, int length) {
		// TODO Auto-generated method stub
		
	}
	
	private void cierto() {
		boolean b=true;
	}
}
